//
//  SetData.m
//  OST
//
//  Created by mac on 13-7-11.
//  Copyright (c) 2013年 mac. All rights reserved.
//

#import "CameraData.h"
#import "Common.h"

@interface CameraData ()

@end

@implementation CameraData

@synthesize resultData;

static CameraData *sharCameraDataInstance = nil;

+(CameraData *) sharedInstance
{
    if (!sharCameraDataInstance) {
        sharCameraDataInstance = [[CameraData alloc]init];
    }
    return sharCameraDataInstance;
}

- (void)requestFinished:(ASIHTTPRequest *)request
{
    NSArray *setStrs= [reciveData componentsSeparatedByString:@"\r\n" ];
    NSMutableArray *result = [NSMutableArray array];
    for (NSString *set in setStrs) {
        NSArray *items = [set componentsSeparatedByString:@"\n"];
        
        if ([items count]==0 || [[items objectAtIndex:0]isEqualToString:@"Success"] || [[items objectAtIndex:0]isEqualToString:@"fail"] || ([[items objectAtIndex:0] rangeOfString:@"="].length==0)) {
            continue;
        }
        NSMutableDictionary *dict = [NSMutableDictionary dictionary];
        for (NSString *item in items) {
            NSArray *values = [item componentsSeparatedByString:@"="];
            [dict setValue:[values objectAtIndex:1] forKey:[[values objectAtIndex:0]lowercaseString]  ];
        }
        [result addObject:dict];
    }
    self.resultData = result;
    [self doneLoadData:resultData];
}

-(void)cleanData
{
    resultData=nil;
}

-(void)reLoadData
{
    self.httpRequest = [Common createHTTPRequest:@"cgi-bin/Get.cgi?get=CAMERA" delegate:self];
    [self.httpRequest startAsynchronous];
}

-(id)getResultData
{
    return resultData;
}

@end
